package com.ostrich.cloud.ostrichBusinessWeb.app.Api;

import com.ostrich.cloud.common.result.Result;
import com.ostrich.cloud.ostrichBusinessWeb.app.Utlis.UserId;
import com.ostrich.cloud.ostrichBusinessWeb.client.OrderWebClient;
import com.ostrich.cloud.ostrichGoodsService.client.SalesClient;
import com.ostrich.cloud.ostrichOrderService.client.OrderManagerClient;
import com.ostrich.cloud.ostrichOrderService.client.param.StoreOrderSearchParam;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import java.util.Date;

@RestController
public class OrderWebApiImp implements OrderWebClient {

    @Resource
    private OrderManagerClient orderManagerClient;

    @Resource
    private SalesClient salesClient;

//    @Override
//    public Result selectOrder(Integer current,Integer size) {
//        StoreOrderSearchParam param=new StoreOrderSearchParam();
//        param.setCurrent(current);
//        param.setSize(size);
//        int parentId = UserId.getParentId();
//        param.setBusinessmanId(parentId);
//        Result result = orderManagerClient.storeOrderSearch(param);
//
//        return result;
//    }

//    @Override
//    public Result selectOrderByNo(Integer current, Integer size, Long orderNo) {
//
//        StoreOrderSearchParam param=new StoreOrderSearchParam();
//        param.setCurrent(current);
//        param.setSize(size);
//        int parentId = UserId.getParentId();
//        param.setBusinessmanId(parentId);
//        param.setOrderNo(orderNo);
//        Result result = orderManagerClient.storeOrderSearch( current, size, orderNo);
//        return result;
//
//    }

    @Override
    public Result selectOrderByTime(Integer current, Integer size, Date startTime, Date finishTime,Long orderNo) {


//        StoreOrderSearchParam param=new StoreOrderSearchParam();
//        param.setCurrent(current);
//        param.setSize(size);
        int parentId = UserId.getParentId();
//        param.setBusinessmanId(parentId);
//        param.setFinishTime(finishTime);
//        param.setStartTime(startTime);
        Result result = orderManagerClient.storeOrderSearch(current,size,startTime,finishTime,4,orderNo);
        return result;

    }

    @Override
    @GlobalTransactional
    public Result putSales(Long orderNo) {
        Result result = orderManagerClient.calOrder(orderNo);
        boolean b = salesClient.putSales(orderNo);
        return result;
    }

    @Override
    public Result putOrder(Long orderNo) {
        Result result = orderManagerClient.finishOrder(orderNo);
        return result;
    }

}
